package translated;

import java.util.List;
import edu.pku.sei.modeler.model.core.*;
import edu.pku.sei.modeler.jet.util.*;
import edu.pku.sei.modeler.model.notation.core.*;
import edu.pku.sei.modeler.model.notation.shape.*;

public class LinkEditPartGen
{
  protected static String nl;
  public static synchronized LinkEditPartGen create(String lineSeparator)
  {
    nl = lineSeparator;
    LinkEditPartGen result = new LinkEditPartGen();
    nl = null;
    return result;
  }

  public final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl;
  protected final String TEXT_1 = "/**" + NL + " * Copyright (c) Software Institute of PKU" + NL + " * All rights reserved. " + NL + " * This program and the accompanying materials" + NL + " * are made available under the terms of the Eclipse Public License v1.0" + NL + " * which accompanies this distribution, and is available at" + NL + " * http://www.eclipse.org/legal/epl-v10.html" + NL + " *" + NL + " */" + NL + "package ";
  protected final String TEXT_2 = ";" + NL + "" + NL + "import java.beans.PropertyChangeEvent;" + NL + "" + NL + "import org.eclipse.draw2d.IFigure;" + NL + "import org.eclipse.draw2d.Graphics;" + NL + "import org.eclipse.draw2d.PolylineDecoration;" + NL + "import org.eclipse.draw2d.PolygonDecoration;" + NL + "import org.eclipse.draw2d.PolylineConnection;" + NL + "import org.eclipse.draw2d.RotatableDecoration;" + NL + "import org.eclipse.draw2d.geometry.PointList;" + NL + "import org.eclipse.draw2d.ColorConstants;" + NL + "import org.eclipse.swt.graphics.Color;" + NL + "" + NL + "import edu.pku.sei.modeler.edit.parts.AbstractLinkEditPart;" + NL + "import edu.pku.sei.modeler.model.structure.MetaShapeElement;" + NL + "" + NL + "/**" + NL + " * @generated" + NL + " *" + NL + " */" + NL + "public class ";
  protected final String TEXT_3 = "Editpart extends AbstractLinkEditPart {" + NL + "\tprivate RotatableDecoration targetDecor;" + NL + "\t" + NL + "\tpublic ";
  protected final String TEXT_4 = "Editpart(MetaShapeElement model) {" + NL + "\t\tsuper(model);" + NL + "\t}" + NL + "\t" + NL + "\tprotected void createEditPolicies() {" + NL + "\t\tsuper.createEditPolicies();" + NL + "\t}" + NL + "\tprivate PolylineConnection getConnection() {" + NL + "\t\treturn (PolylineConnection)getFigure();" + NL + "\t}" + NL + "\t" + NL + "\t";
  protected final String TEXT_5 = NL + "\tprotected IFigure createFigure() {" + NL + "\t\tPolylineConnection conn = new PolylineConnection();\t" + NL + "\t\tconn.setLineStyle(";
  protected final String TEXT_6 = ");" + NL + "\t\treturn conn;" + NL + "\t}" + NL + "\t";
  protected final String TEXT_7 = NL + "\tprivate PolylineDecoration createDecoration () {" + NL + "\t\tPolylineDecoration decoration = new PolylineDecoration();" + NL + "\t\tdecoration.setScale(10, 5);" + NL + "\t\treturn decoration;" + NL + "\t}" + NL + "\t";
  protected final String TEXT_8 = NL + "\tprivate PolygonDecoration createDecoration () {" + NL + "\t\tPolygonDecoration decoration = new PolygonDecoration();" + NL + "\t\tdecoration.setScale(10, 5);" + NL + "\t\tdecoration.setBackgroundColor(ColorConstants.white);" + NL + "\t\treturn decoration;" + NL + "\t}" + NL + "\t";
  protected final String TEXT_9 = NL + "\tprivate PolygonDecoration createDecoration () {" + NL + "\t\tPolygonDecoration decoration = new PolygonDecoration();" + NL + "\t\tPointList points = new PointList();" + NL + "\t\tpoints.addPoint(0, 0);" + NL + "\t\tpoints.addPoint(-1, -1);" + NL + "\t\tpoints.addPoint(-2, 0);" + NL + "\t\tpoints.addPoint(-1, 1);" + NL + "\t\tdecoration.setTemplate(points);" + NL + "\t\tdecoration.setScale(10, 5);" + NL + "\t\tdecoration.setBackgroundColor(ColorConstants.white);" + NL + "\t\treturn decoration;" + NL + "\t}" + NL + "\t";
  protected final String TEXT_10 = NL + "\tprivate PolygonDecoration createDecoration () {" + NL + "\t\tPolygonDecoration decoration = new PolygonDecoration();" + NL + "\t\tdecoration.setScale(10, 5);" + NL + "\t\tdecoration.setBackgroundColor(ColorConstants.black);" + NL + "\t\treturn decoration;" + NL + "\t}" + NL + "\t";
  protected final String TEXT_11 = NL + "\tprivate PolygonDecoration createDecoration () {" + NL + "\t\tPolygonDecoration decoration = new PolygonDecoration();" + NL + "\t\tPointList points = new PointList();" + NL + "\t\tpoints.addPoint(0, 0);" + NL + "\t\tpoints.addPoint(-1, -1);" + NL + "\t\tpoints.addPoint(-2, 0);" + NL + "\t\tpoints.addPoint(-1, 1);" + NL + "\t\tdecoration.setTemplate(points);" + NL + "\t\tdecoration.setScale(10, 5);" + NL + "\t\tdecoration.setBackgroundColor(ColorConstants.black);" + NL + "\t\treturn decoration;" + NL + "\t}" + NL + "\t";
  protected final String TEXT_12 = NL + "\tprivate PolylineDecoration createDecoration () {" + NL + "\t\treturn null;" + NL + "\t}" + NL + "\t";
  protected final String TEXT_13 = NL + "\tprotected IFigure createFigure() {" + NL + "\t\tPolylineConnection conn = new PolylineConnection();\t" + NL + "\t\treturn conn;" + NL + "\t}" + NL + "\t" + NL + "\tprivate PolylineDecoration createDecoration () {" + NL + "\t\tPolylineDecoration decoration = new PolylineDecoration();" + NL + "\t\tdecoration.setScale(10, 5);" + NL + "\t\treturn decoration;" + NL + "\t}" + NL + "\t";
  protected final String TEXT_14 = NL + "\t" + NL + "\tprotected void handlePropertyChanged(PropertyChangeEvent event) {" + NL + "\t\t" + NL + "\t}" + NL + "\tprotected void refreshVisuals() {" + NL + "\t\tsuper.refreshVisuals();" + NL + "\t\tupdateTargetDecoration();" + NL + "\t}" + NL + "\t" + NL + "\tprivate void updateTargetDecoration() {" + NL + "\t\tif (targetDecor == null) {" + NL + "\t\t\ttargetDecor = createDecoration();" + NL + "\t\t\tgetConnection().setTargetDecoration(targetDecor);" + NL + "\t\t}" + NL + "\t}" + NL + "}";
  protected final String TEXT_15 = NL;

  public String generate(Object argument)
  {
    final StringBuffer stringBuffer = new StringBuffer();
     MetaClass cls = (MetaClass) argument; 
    stringBuffer.append(TEXT_1);
    stringBuffer.append(ModelerConstants.pkgBase + "." + ModelerConstants.editpartBase);
    stringBuffer.append(TEXT_2);
    stringBuffer.append(cls.getName());
    stringBuffer.append(TEXT_3);
    stringBuffer.append(cls.getName());
    stringBuffer.append(TEXT_4);
    
	//get notation
	Notation notation = null;
	CoreMetaModel cmm = (CoreMetaModel)cls.getModel();
	List nlist = cmm.getNotations();
	for (int i = 0; i < nlist.size();i++) {
		Notation n = (Notation)nlist.get(i);
		if (n.getModelID() == cls.getElementID()) {
			notation = n;
			break;
		}//end if
	}//end for
	//generate line
	if (notation != null && notation.getNotations().size() != 0) {
		List notations = notation.getNotations();
		ConnectionTemplate con = (ConnectionTemplate)notations.get(0);	
	
    stringBuffer.append(TEXT_5);
    stringBuffer.append(con.getLineStyle());
    stringBuffer.append(TEXT_6);
    
	//generate target decoration
		if (con.getEndStyle() == ConnectionTemplate.END_ARROW) {
	
    stringBuffer.append(TEXT_7);
    
		}
		else if (con.getEndStyle() == ConnectionTemplate.END_TRIANGLE) {
	
    stringBuffer.append(TEXT_8);
    
		}
		else if (con.getEndStyle() == ConnectionTemplate.END_DIAMOND) {
	
    stringBuffer.append(TEXT_9);
    
		}
		else if (con.getEndStyle() == ConnectionTemplate.END_SOLIDTRIANGLE) {
	
    stringBuffer.append(TEXT_10);
    
		}
		else if (con.getEndStyle() == ConnectionTemplate.END_SOLIDDIAMOND) {
	
    stringBuffer.append(TEXT_11);
    
		}
		else {
	
    stringBuffer.append(TEXT_12);
    
		}
	}
	else {
	
    stringBuffer.append(TEXT_13);
    
	}
	
    stringBuffer.append(TEXT_14);
    stringBuffer.append(TEXT_15);
    return stringBuffer.toString();
  }
}
